<template>
    <view class="container">
        <view class="header-tabs">
            <view @tap="__e" :class="['tab-item', current === 0 ? 'active' : '']" :data-current="0" :data-event-opts="[['tap', [['currentChange', ['$event']]]]]">未使用</view>
            <view @tap="__e" :class="['tab-item', current === 1 ? 'active' : '']" :data-current="1" :data-event-opts="[['tap', [['currentChange', ['$event']]]]]">已使用</view>
            <view @tap="__e" :class="['tab-item', current === 2 ? 'active' : '']" :data-current="2" :data-event-opts="[['tap', [['currentChange', ['$event']]]]]">已过期</view>
        </view>
        <view class="swiper-wrapper">
            <swiper @change="__e" :current="current" :data-event-opts="[['change', [['currentChange2', ['$event']]]]]">
                <swiper-item v-for="(item, index) in $root.l0" :key="index">
                    <scroll-view @scrolltolower="__e" :data-event-opts="[['scrolltolower', [['getUserCoupons', ['$event']]]]]" :scrollY="true">
                        <view class="list">
                            <coupon-item
                                :active="item[$orig] === 'valid' ? 1 : 0"
                                @__l="__l"
                                :coupon="coupon"
                                :unActiveText="unActiveText[item[$orig]]"
                                :vueId="'46e816cb-1-' + index + '-' + __i0__"
                                v-for="(coupon, __i0__) in dataList[index].list"
                                :key="__i0__"
                            ></coupon-item>
                            <no-data @__l="__l" :title="arry[index]" :vueId="'46e816cb-2-' + index" v-if="item.g0"></no-data>
                        </view>
                    </scroll-view>
                </swiper-item>
            </swiper>
        </view>
        <navigator url="/pages/code/index">
            <view class="footer">
                <view class="footer-button" hoverClass="none"></view>
            </view>
        </navigator>
    </view>
</template>

<script>
import noData from '@/components/NoData/NoData';
import couponItem from '@/pages/myCoupons/components/CouponItem';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/myCoupons/index'],
    {
        '0a69': function (t, e, n) {
            'use strict';

            (function (t, e) {
                var a = n('4ea4');
                n('18ba');
                a(n('66fd'));
                var r = a(n('1457'));
                t.__webpack_require_UNI_MP_PLUGIN__ = n;
                e(r.default);
            }.call(this, n('bc2e').default, n('543d').createPage));
        },
        1457: function (t, e, n) {
            'use strict';

            n.r(e);
            var a = n('7a93');
            var r = n('7217');
            for (var o in r) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        n.d(e, t, function () {
                            return r[t];
                        });
                    })(o);
                }
            }
            n('2333');
            var i = n('f0c5');
            var u = Object(i.a)(r.default, a.b, a.c, false, null, null, null, false, a.a, void 0);
            e.default = u.exports;
        },
        2333: function (t, e, n) {
            'use strict';

            var a = n('bfd3');
            n.n(a).a;
        },
        7217: function (t, e, n) {
            'use strict';

            n.r(e);
            var a = n('95f0');
            var r = n.n(a);
            for (var o in a) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        n.d(e, t, function () {
                            return a[t];
                        });
                    })(o);
                }
            }
            e.default = r.a;
        },
        '7a93': function (t, e, n) {
            'use strict';

            n.d(e, 'b', function () {
                return r;
            });
            n.d(e, 'c', function () {
                return o;
            });
            n.d(e, 'a', function () {
                return a;
            });
            var a = {
                NoData: function () {
                    return n.e('components/NoData/NoData').then(n.bind(null, 'cafe'));
                }
            };
            var r = function () {
                var that = this;
                var e =
                    (that.$createElement,
                    that._self._c,
                    that.__map(that.types, function (e, n) {
                        return {
                            $orig: that.__get_orig(e),
                            g0: that.dataList[n].init && !that.dataList[n].list.length
                        };
                    }));
                that.$mp.data = Object.assign(
                    {},
                    {
                        $root: {
                            l0: e
                        }
                    }
                );
            };
            var o = [];
        },
        '95f0': function (t, e, n) {
            'use strict';

            (function (t) {
                var a = n('4ea4');
                Object.defineProperty(e, '__esModule', {
                    value: true
                });
                e.default = void 0;
                var r = a(n('2eee'));
                var o = a(n('448a'));
                var i = a(n('c973'));
                var u = {
                    components: {
                        CouponItem: function () {
                            Promise.all([n.e('common/vendor'), n.e('pages/myCoupons/components/CouponItem')])
                                .then(
                                    function () {
                                        return resolve(n('8db6'));
                                    }.bind(null, n)
                                )
                                .catch(n.oe);
                        },
                        NoData: function () {
                            n.e('components/NoData/NoData')
                                .then(
                                    function () {
                                        return resolve(n('cafe'));
                                    }.bind(null, n)
                                )
                                .catch(n.oe);
                        }
                    },
                    data: function () {
                        return {
                            codekey: '',
                            dataList: [],
                            current: 0,
                            unActiveText: {
                                valid: '立即使用',
                                used: '已使用',
                                expired: '已过期'
                            },
                            types: ['valid', 'used', 'expired'],
                            arry: ['暂无未使用的优惠券', '暂无已使用的优惠券', '暂无已过期的优惠券'],
                            itempage: 1
                        };
                    },
                    filters: {
                        dateFormat: function (t) {
                            return t ? moment(t).format('YYYY/YY/DD') : '';
                        },
                        dateFormat2: function (t) {
                            return t ? moment(t).format('YY/DD') : '';
                        }
                    },
                    onLoad: function (t) {
                        var that = this;
                        this.current = t.current ? parseInt(t.current) : 0;
                        this.types.forEach(function (t) {
                            that.dataList.push({
                                list: [],
                                type: t,
                                page: 1,
                                per_page: 10,
                                total: 0,
                                init: false
                            });
                        });
                        this.getUserCoupons();
                    },
                    methods: {
                        handleSubmit: function (e) {
                            var that = this;
                            return (0, i.default)(
                                r.default.mark(function e() {
                                    return r.default.wrap(function (e) {
                                        for (;;) {
                                            switch ((e.prev = e.next)) {
                                                case 0:
                                                    if (that.codekey) {
                                                        e.next = 2;
                                                        break;
                                                    }
                                                    return e.abrupt('return');
                                                case 2:
                                                    t.showLoading();
                                                    e.next = 5;
                                                    return that
                                                        .$http({
                                                            url: '/pick-coupon',
                                                            method: 'post',
                                                            data: {
                                                                code: that.codekey
                                                            }
                                                        })
                                                        .catch(function (e) {
                                                            t.hideLoading();
                                                        });
                                                case 5:
                                                    e.sent;
                                                    that.getUserCoupons();
                                                    t.showToast({
                                                        title: '领取成功',
                                                        icon: 'none'
                                                    });
                                                    t.hideLoading();
                                                    that.codekey = '';
                                                case 10:
                                                case 'end':
                                                    return e.stop();
                                            }
                                        }
                                    }, e);
                                })
                            )();
                        },
                        currentChange: function (t) {
                            var e = t.currentTarget.dataset.current;
                            if (e !== this.current) {
                                this.current = e;
                                this.dataList[this.current].init || this.getUserCoupons();
                            }
                        },
                        currentChange2: function (t) {
                            var e = t.detail.current;
                            if (e !== this.current) {
                                this.current = e;
                                this.dataList[this.current].init || this.getUserCoupons();
                            }
                        },
                        getUserCoupons: function () {
                            var that = this;
                            var e = this.dataList[this.current];
                            e.page += 1;
                            this.$api
                                .emit('user.coupon.list', {
                                    type: e.type,
                                    page: e.page - 1,
                                    per_page: e.per_page
                                })
                                .then(function (e) {
                                    var n;
                                    (n = that.dataList[that.current].list).push.apply(n, (0, o.default)(e.data.list));
                                    that.dataList[that.current].total = e.data.item_total;
                                    that.dataList[that.current].init = true;
                                });
                        }
                    }
                };
                e.default = u;
            }.call(this, n('543d').default));
        },
        bfd3: function (t, e, n) {}
    },
    [['0a69', 'common/runtime', 'common/vendor']]
]);
</script>
<style>
@import './index.css';
</style>
